﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TransCend.Result
{
    public class JsTree : AbsJsTree
    {
        private string iconstr = null;
        private IList<JsTree> childrenlist = null;
        private Dictionary<string, JsTree> childrenMap = new Dictionary<string, JsTree>();
        
        public override string icon
        {
            get { return iconstr != null ? iconstr : children == null ? "fa fa-file icon-state-warning" : ""; }
            set { iconstr = value; }
        }

        public IList<JsTree> children
        {
            get { return childrenlist; }
        }

        public void addChild(JsTree t)
        {
            if (childrenlist == null) childrenlist = new List<JsTree>();
            if (!childrenMap.ContainsKey(t.id))
            {
                childrenlist.Add(t);
                childrenMap[t.id] = t;
            }
            else
            {
                if (t.state[Selected])
                {
                    childrenMap[t.id].SetSelected(true);
                }
            }
        }

    }
}
